<?php

namespace app\common\command;

use app\common\model\Bill;
use app\common\model\BillTitle;
use app\common\model\Order;
use fast\Nuo;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Env;
use think\Exception;
use think\Queue;

class OpenRedBill extends Command
{

    protected function configure()
    {
        $this->setName('open-red-bill');
    }

    protected function execute(Input $input, Output $output)
    {
        $list = Bill::where(['client_status'=>4])->select()->toArray();
        if (!empty($list)){
            $nuo = new Nuo();
            foreach ($list as $v){
                $arr = $nuo->queryInvoiceRedConfirm([
                    'identity'=>0,//操作方身份： 0销方 1购方
                    'billId'=>$v['redBillId'],//红字确认单申请号
                ]);
                if ($arr['code'] == '0'){
                    continue;
                }elseif ($arr['code'] == 'E0000'){//红字确认单查询成功
                    if ($arr['result']['list'][0]['billStatus'] == '01' || $arr['result']['list'][0]['billStatus'] == '04'){ //确认单状态为无需确认和购销双方已确认,则调快捷冲红接口开红票
                        Queue::push(\app\job\RedBill::class,['member_id'=>$v['member_id'],'bill_id'=>$v['id'],'billNo'=>$arr['result']['list'][0]['billNo'],'billUuid'=>$arr['result']['list'][0]['billUuid']],'message');
                    }
                }else{
                    continue;
                }
            }
        }
        $output->info("Opend Bill Successed!");
    }


}
